﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace SomethingSpacial.Views.MixItUp
{
    public partial class EventTimerControl : UserControl
    {
        //TODO: Will be replaced with the next event date from database
        //Current value: MIX start date
        DateTime dtEventDate = new DateTime(2010, 03, 15, 08, 00, 00);
        public string daysLeft = "";

        public EventTimerControl()
        {
            // Required to initialize variables
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(EventTimerControl_Loaded);

        }

        public void SetDateTime(DateTime dateTmeSelected)
        {
            dtEventDate = dateTmeSelected;
            TimerTextBlock.Visibility = Visibility.Collapsed;
            //DispatcherTimer timer = new DispatcherTimer();
            //timer.Interval = new TimeSpan(0, 0, 1);
            //timer.Tick += new EventHandler(timer_Tick);
            //timer.Start();

            /*TODO: Seconds add instant interactivity; yet are not required for display*/
            TimeSpan timeLeft = dtEventDate.Subtract(DateTime.Now);
            TimerTextBlock.Text = string.Format("{0:00}:{1:00}:{2:00}:{3:00}",
                timeLeft.Days.ToString("#00"),
                timeLeft.Hours.ToString("#00"),
                timeLeft.Minutes.ToString("#00"),
                timeLeft.Seconds.ToString("#00"));

            TimerTextBlock.Text = timeLeft.Days.ToString() + " days " + timeLeft.Hours.ToString() + " hours " + timeLeft.Minutes.ToString() + " minutes";



            TimerTextBlock.Visibility = Visibility.Visible;
            TimerShadowTextBlock.Text = TimerTextBlock.Text;



        }

        void EventTimerControl_Loaded(object sender, RoutedEventArgs e)
        {
            TimerTextBlock.Visibility = Visibility.Collapsed;
            //DispatcherTimer timer = new DispatcherTimer();
            //timer.Interval = new TimeSpan(0, 0, 1);
            //timer.Tick += new EventHandler(timer_Tick);
            //timer.Start();

            /*TODO: Seconds add instant interactivity; yet are not required for display*/
            TimeSpan timeLeft = dtEventDate.Subtract(DateTime.Now);
            TimerTextBlock.Text = string.Format("{0:00}:{1:00}:{2:00}:{3:00}",
                timeLeft.Days.ToString("#00"),
                timeLeft.Hours.ToString("#00"),
                timeLeft.Minutes.ToString("#00"),
                timeLeft.Seconds.ToString("#00"));
            //TimerTextBlock.Visibility = Visibility.Visible;
            TimerShadowTextBlock.Text = TimerTextBlock.Text;

        }

        void timer_Tick(object sender, EventArgs e)
        {
            

            /*TODO: Seconds add instant interactivity; yet are not required for display*/
            TimeSpan timeLeft = dtEventDate.Subtract(DateTime.Now);
            TimerTextBlock.Text = string.Format("{0:00}:{1:00}:{2:00}:{3:00}",
                timeLeft.Days.ToString("#00"),
                timeLeft.Hours.ToString("#00"), 
                timeLeft.Minutes.ToString("#00"),
                timeLeft.Seconds.ToString("#00"));
            TimerShadowTextBlock.Text = TimerTextBlock.Text;

        }

    }
}
